<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>嘉童游乐中心-库存调整</title>
<jsp:include page="/common/commonCss.jsp" />
<jsp:include page="/common/commonJs.jsp" />
<script src="${basePath}commonJs/tags/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var branId = '${branId}';
		if (branId == 'ZB') {
			$("#branName").prepend("<option value=''>" + "全部" + "</option>");
			$("#fkBranId1").prepend("<option value=''>" + "请选择" + "</option>");
		}
		var objSelect = document.getElementById("branName");
		for (var i = 0; i < objSelect.options.length; i++) {
			if (objSelect.options[i].value == '') {
				objSelect.options[i].selected = true;
			}
		}
		var objSelect1 = document.getElementById("fkBranId1");
		for (var i = 0; i < objSelect1.options.length; i++) {
			if (objSelect1.options[i].value == '') {
				objSelect1.options[i].selected = true;
			}
		}
		initTab("sysForm");
	});

	function initTab(formId) {
		var pkBcodeId = $.trim($("#pkBcodeId").val());
		var fkBranId = document.getElementById("branName").value;
		var status = document.getElementById("status").value;
		document.getElementById("BcodeIdHidden").value = pkBcodeId;
		document.getElementById("branNameHidden").value = fkBranId;
		document.getElementById("statusHidden").value = status;
		var form = $("#" + formId);//获取一个form的jquery对象
		var pagebean = new PageBean(form); //实例化一个Pagebean对象，并且设置form对象
		pagebean.setTableId("table1"); //设置要分页的table的id属性
		pagebean.setCallback(initTable); //回调函数
		pagebean.setFootId("pagefoot"); //foot div的id
		setPagebeanObj(pagebean); //全局化pageBean对象
		pagebean.doPage(); //执行分页
	}

	function doChecked(o) {
		$("[name = box]:checkbox").attr("checked",
				o.attr("checked") == 'checked');
	}

	$(function() {
		$("#selectAll").bind("click", function() {
			doChecked($(this));
		});
		//停用条码
		$("#stopBatch").bind("click", function() {
			var str = document.getElementsByName("box");
			var status = "1";
			var length = str.length;
			var chestr = "";
			for (var i = 0; i < length; i++) {
				if (str[i].checked) {
					chestr = chestr + str[i].value + ",";
				}

			}
			if (chestr != "") {
				$.ajax({

					url : '${basepath}batch.shtml',
					type : "post",
					data : {
						"chestr" : chestr,
						"status" : status
					},
					dataType : "text",
					async : false,
					success : function(result) {
						if (result == "success") {
							alertInfo("成功停用");
							$("#selectAll").attr("checked", false);
							initTab("sysForm");

						}else{
							alertInfo("以下条码正在使用，不能停用；【"+result+"】");
							$("#selectAll").attr("checked", false);
							initTab("sysForm");

						}
					},
					error : function(XMLHttpRequest) {
						ajaxError(XMLHttpRequest);
					}
				});
			} else {
				alertError("请选择需要停用的条目！");
			}

		});

		//启用条码
		$("#startBatch").bind("click", function() {
			var str = document.getElementsByName("box");
			var status = "0";
			var length = str.length;
			var chestr = "";
			for (var i = 0; i < length; i++) {
				if (str[i].checked) {
					chestr = chestr + str[i].value + ",";
				}

			}
			if (chestr != "") {
				$.ajax({

					url : '${basepath}batch.shtml',
					type : "post",
					data : {
						"chestr" : chestr,
						"status" : status
					},
					dataType : "text",
					async : false,
					success : function(result) {
						if (result == "success") {
							alertInfo("成功启用");
							$("#selectAll").attr("checked", false);
							initTab("sysForm");

						}
					},
					error : function(XMLHttpRequest) {
						ajaxError(XMLHttpRequest);
					}
				});
			} else {
				alertError("请选择需要启用的条目！");
			}

		});
	});

	function initTable(data) {
		if (data == null) {
			return;
		}
		$.each(data, function(ind, obj) {
			var status = obj.status;
			if (status == 0) {
				status = "启用";
			}
			if (status == 1) {
				status = "停用";
			}
			if (status == 2) {
				status = "占用";
			}
			var pkBcodeId = obj.pkBcodeId;
			var htm = "<tr>";
			htm += "<td>"
					+ "<input type='checkbox' name='box'  value="+pkBcodeId+">"
					+ "</td>";
			htm += "<td>" + obj.branName + "</td>";
			htm += "<td>" + obj.barCode + "</td>";
			htm += "<td>" + status + "</td></tr>";
			$("#table1").find("tr:eq(" + ind + ")").after(htm);
		});
		$("#selectAll").attr("checked", false);

	}

	function selectBcode(formId) {
		$("#" + formId + " input:hidden[name='pageNo']").val(1);
		initTab(formId);
	}
	//批量生成条码
	function saveBatch() {
		var fbranId = $("#fkBranId1").val();
		var trueFlag = true;
		if (fbranId == "") {
			alertWarning("请选择门店。");
			document.getElementById("fkBranId1").value = "";
			refreshSelect();
			trueFlag = false;
			return;
		}
		var tiaoCount = document.getElementById("tiaomacount");
		if (tiaoCount.value == "") {
			alertWarning(' 生成数量文本框 处 请输入1~~500 的数字！');
			tiaoCount.value = "";
			tiaoCount.focus();
			trueFlag = false;
			return;
		}
		if (isNaN(tiaoCount.value)) {//判断 是否 为数字
			alertWarning('生成数量文本框 处  请输入1~~500 的数字！');
			tiaoCount.value = "";
			tiaoCount.focus();
			trueFlag = false;
			return;
		}
		if (tiaoCount.value > 500) {
			alertWarning('生成数量文本框 处  请输入1~~500 的数字！');
			tiaoCount.value = "";
			tiaoCount.focus();
			trueFlag = false;
			return;
		}
		if (trueFlag) {
			var url = '${basePath }SysBarCode/saveBatch.shtml?parType=0&branId='
					+ fbranId + '&saveCount=' + tiaoCount.value;
			$.ajax({
				url : url,
				type : 'get',
				async : false,
				success : function(msg) {
					if (msg == "success") {
						alertInfo("成功批量生成条码。");
					} else {
						alertError("系统错误，批量生成失败。");
					}
					$('#q').window('close');
					initTab("sysForm");
				},
				error : function(XMLHttpRequest) {
					ajaxError(XMLHttpRequest);
				}
			});
		}

	}

	//批量导出条码
	function download() {
		var str = document.getElementsByName("box");
		var length = str.length;
		var chestr = "";
		for (var i = 0; i < length; i++) {
			if (str[i].checked) {
				chestr = chestr + str[i].value + ",";
			}

		}
		if (chestr != "") {
			$("#chestr").val(chestr);
			$("#form2").submit();
		}
	}
</script>

</head>
<body class="bg">
	<div class="content m_auto">
		<div class="content_l mt10">
			<ul>

				<shiro:hasPermission name="authority/role/home.shtml">
					<li><a href="${basePath}authority/role/home.shtml"><i
							class="nav_icon_u"></i><br>角色管理</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="authority/user/home.shtml">
					<li><a href="${basePath}authority/user/home.shtml"><i
							class="nav_icon_t"></i><br>用户管理</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="SalesRelation/mem.shtml">
					<li><a href="${basePath}SalesRelation/mem.shtml"><i
							class="nav_icon_s"></i><br>销售关联会员</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="ParRoomDetail/ParRoom.shtml">
					<li><a href="${basePath}ParRoomDetail/ParRoom.shtml"><i
							class="nav_icon_r"></i><br>房间管理</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="SysBarCode/system.shtml">
					<li class="content_hover"><a
						href="${basePath }SysBarCode/system.shtml"><i
							class="nav_icon_q"></i><br>条码维护</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="WfmAuthorize/toShenP.shtml">
					<li><a href="${basePath}WfmAuthorize/toShenP.shtml"><i
							class="nav_icon_s"></i><br>审批转授权</a></li>
				</shiro:hasPermission>
				<shiro:hasPermission name="holiday/sysHoliday.shtml">
					<li><a href="${basePath}holiday/sysHoliday.shtml"><i
							class="nav_icon_q"></i><br>节假日管理</a></li>
				</shiro:hasPermission>
			</ul>
		</div>
		<div class="content_r mt10">
			<!---- 内容 --->
			<div class="file_single_dl fixed p20">
				<dl>
					<dd>
						<label>所属门店：</label>
						<div class="uboxstyle">
							<select name="branName" id="branName">
								<c:forEach items="${list}" var="List">
									<option value="${List.pkBranId}">${List.branName}</option>
								</c:forEach>
							</select>
						</div>
					</dd>

					<dd>
						<label>条码编号：</label><input type="text" class="iput_t w200"
							id="pkBcodeId">
					</dd>
					<dd>
						<label>状态：</label>
						<div class="uboxstyle">
							<select name="status" id="status">
								<option value=''>全部</option>
								<option value='0'>启用</option>
								<option value='1'>停用</option>
								<option value='2'>占用</option>
							</select>
						</div>
					</dd>


					<dd class="fr w630">
						<input type="button" class="btn fr ml10" value="查询"
							onclick="selectBcode('sysForm')"><input type="button"
							class="btn fr ml10" value="批量生成" onclick="$('#q').window('open')">
						<form action="${basePath}SysBarCode/downLoadBcode.shtml"
							method="post">
							<shiro:hasPermission name="leave:daochuTM">
								<input type="submit" class="btn fr ml10" value="导出全部条码">
							</shiro:hasPermission>
						</form>
						<form action="${basePath}SysBarCode/downLoadBcode1.shtml"
							method="post" id="form2">
							<input type="button" class="btn fr ml10" value="批量导出条码"
								onclick="download()"> <input type="hidden" id="chestr"
								name="chestr">
						</form>
						<input type="button" value="停用" class="btn w70 fr ml10"
							id="stopBatch"> <input type="button" value="启用"
							class="btn w70 fr ml10" id="startBatch">
					</dd>
				</dl>

			</div>

			<form action="${basePath}SysBarCode/selectSysBarCode.shtml"
				method="post" id="sysForm">
				<input type="hidden" name="pageNo" value="1"> <input
					type="hidden" name="pageSize" value="10"> <input
					type="hidden" name="barCode" id="BcodeIdHidden"> <input
					type="hidden" name="fkBranId" id="branNameHidden"> <input
					type="hidden" name="status" id="statusHidden">

			</form>
			<div class="m10">
				<table class="table" id="table1">
					<tr>
						<th><input type="checkbox" id="selectAll" class="mr5">选择</th>
						<th>所属门店</th>
						<th>条码编号</th>
						<th>状态</th>
					</tr>
				</table>
				<!----翻页----->
				<div class="page fr m10" id="pagefoot"></div>
				<!----翻页----->
			</div>
			<!---- 内容 --->
		</div>
	</div>
	





	<!---弹出层--->
	<div id="q" class="easyui-window" title="批量生成条形码"
		data-options="modal:true,closed:true,iconCls:'icon-save'"
		style="width: 600px; height: 300px; position: relative;">
		<ul class="w360_c yonh_x_ul">
			<li><label>所属门店：</label> <!----select--->
				<div class="uboxstyle">
					<select name="fkBranId1" id="fkBranId1">
						<c:forEach items="${list}" var="List">;
	                            <option value="${List.pkBranId}">
								${List.branName}</option>
						</c:forEach>
					</select>
				</div>
				<span class="color_red ml5">*</span> <!----select---></li>
			<li><label>生成数量：</label><input name="tiaomCount" maxlength="3"
				id="tiaomacount" type="text" class="iput_t w200"> <span
				class="color_red ml5">*</span></li>
		</ul>
		<div class="btm_btn btm_bg">
			<dl>
				<dd>
					<input type="button" class="btn" onclick="saveBatch()" value="确定">
				</dd>
				<dd>
					<input type="button" class="btn" onclick="$('#q').window('close')"
						value="取消">
				</dd>
			</dl>
		</div>
	</div>
	<!---弹出层--->




</body>
</html>



